
public class Search2D {
	
	  public boolean searchMatrix(int[][] matrix, int target) {
          int n=matrix.length;
	        int m=matrix[0].length;
	        int x=0;
	        int y=m-1;
	        while(x>=0&&x<n&&y>=0&&y<m){
	        	if(matrix[x][y]==target)
	        		return true;
	        	else if(matrix[x][y]>target)
	        		y--;
	        	else 
	        		x++;
	        }
	      return false; 
    }
}
